@nice2dev/ui 1.3.9 → 1.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/NiceColorPicker-BLwYNSXJ.cjs +1 -0
  3. package/dist/NiceColorPicker-DS59tNkP.js +552 -0
  4. package/dist/NiceDataGrid-CL2_7fS7.cjs +10 -0
  5. package/dist/NiceDataGrid-CpJrRN_H.js +2269 -0
  6. package/dist/NiceForm-BQj-K7p7.cjs +1 -0
  7. package/dist/NiceForm-HQ4h7hX_.js +5023 -0
  8. package/dist/NiceGantt-BygumlaY.cjs +1 -0
  9. package/dist/NiceGantt-DTC7OH-v.js +334 -0
  10. package/dist/NiceHtmlEditor-BtpuaLln.js +901 -0
  11. package/dist/NiceHtmlEditor-C1OVtLQ6.cjs +10 -0
  12. package/dist/NiceMention-CVxxCVtQ.js +11668 -0
  13. package/dist/NiceMention-Te66Oid1.cjs +430 -0
  14. package/dist/NiceModuleLifecyclePanel-DCrFyUH8.cjs +1 -0
  15. package/dist/NiceModuleLifecyclePanel-Mt80MdET.js +7441 -0
  16. package/dist/NicePagination-CKsAP38Q.cjs +1 -0
  17. package/dist/NicePagination-zOed5QxG.js +202 -0
  18. package/dist/NicePivotGrid-Clue9FM5.js +1184 -0
  19. package/dist/NicePivotGrid-Cnkr9WkC.cjs +152 -0
  20. package/dist/NiceSavedQueryPanel-NgG58w6i.js +6226 -0
  21. package/dist/NiceSavedQueryPanel-lTWY2plm.cjs +587 -0
  22. package/dist/NiceScheduler-BWwqFKEc.js +1712 -0
  23. package/dist/NiceScheduler-DqWEJU7g.cjs +5 -0
  24. package/dist/NiceSelect-BNPXs6FQ.cjs +1 -0
  25. package/dist/NiceSelect-DEruWHan.js +495 -0
  26. package/dist/NiceWindow-D3V7A69Q.js +2247 -0
  27. package/dist/NiceWindow-pgR4c-kQ.cjs +1 -0
  28. package/dist/core-lazy-Bjdu111n.js +351 -0
  29. package/dist/core-lazy-Bx_8BOlG.cjs +1 -0
  30. package/dist/data.cjs +1 -1
  31. package/dist/data.d.ts +46 -5
  32. package/dist/data.mjs +3 -3
  33. package/dist/devops-CqhA0rjL.js +9130 -0
  34. package/dist/devops-cgRBnZVX.cjs +18 -0
  35. package/dist/devops.cjs +1 -1
  36. package/dist/devops.mjs +1 -1
  37. package/dist/editors.cjs +1 -1
  38. package/dist/editors.mjs +7 -7
  39. package/dist/feedback.cjs +1 -1
  40. package/dist/feedback.mjs +1 -1
  41. package/dist/index.cjs +108 -108
  42. package/dist/index.css +1 -1
  43. package/dist/index.d.ts +51 -8
  44. package/dist/index.mjs +13739 -13579
  45. package/dist/lazy.cjs +1 -1
  46. package/dist/lazy.mjs +15 -15
  47. package/dist/navigation.cjs +1 -1
  48. package/dist/navigation.d.ts +2 -0
  49. package/dist/navigation.mjs +3 -3
  50. package/dist/no-code-BQqK8mvU.cjs +331 -0
  51. package/dist/no-code-Cppb-xz3.js +8320 -0
  52. package/dist/no-code.cjs +1 -1
  53. package/dist/no-code.mjs +1 -1
  54. package/dist/overlays.cjs +1 -1
  55. package/dist/overlays.mjs +1 -1
  56. package/dist/pickerCommons-BA3-D5RC.js +663 -0
  57. package/dist/pickerCommons-KrBqCBDn.cjs +1 -0
  58. package/dist/style.css +1 -1
  59. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # [1.0.27] — 2026-06-07
2
2
 
3
+ ## 1.3.10
4
+
5
+ ### Patch Changes
6
+
7
+ - e5b7da8: **NiceTreeGrid: lazy children, whole subtrees, own selection summary. Test ids on 61 more controls.**
8
+
9
+ - **`loadChildren` + `hasChildren`:** a row can get its children when it is first opened. While they
10
+ load, a "Loading…" row stands under it. A failed load shows a row with a retry button. The grid
11
+ keeps what it loaded.
12
+ - Flat rows can bring deeper levels along (`parentKeyField`), nested rows through
13
+ `childrenField`.
14
+ - A row that is checked before it loads checks its children when they arrive.
15
+ - `hasChildren` alone (without `loadChildren`) gives an expander and a loading row until the host
16
+ adds the children to `data`.
17
+ - **Whole subtrees:** `rowActions={['expandSubtree']}` adds a row button that opens everything below
18
+ a row (loading lazy rows on the way) and closes it all once it is open. Alt- or Shift-click on an
19
+ expander and Shift+→ / Shift+← do the same without the button.
20
+ - **`checkedSummary`:** `false` hides "{checked} of {total} selected"; a function renders your own
21
+ from `checked`, `total`, `leafKeys` and `rows`, e.g. to count an item that has a row under several
22
+ parents once.
23
+ - **Expanding while searching:** rows the user opens or closes during a search now go through
24
+ `onExpandedChange` and stay that way after the search. The rows the search opens by itself are
25
+ still not reported and close again.
26
+ - **Fix: `*` opened only the last sibling:** each sibling's change started from the same set. It now
27
+ opens all of them.
28
+ - **Test ids:** `NiceBaseProps` declares `data-testid`, and 61 controls built on it dropped it. Among
29
+ them are NiceCard, NiceCheckbox, NiceToggle, NiceTabs, NiceAccordion, NiceBreadcrumb,
30
+ NiceTreeView, NiceTreeList, NiceForm, NicePagination and NiceMenu. They all render it on their
31
+ root element now.
32
+ - `NiceCard` also takes `testId` and forwards `id` to the card element.
33
+ - The CI gate `Test ids on standard controls` now covers `NiceBaseProps` controls too, and
34
+ counts a `{...rest}` spread on an element as forwarding.
35
+
36
+ - Updated dependencies [e5b7da8]
37
+ - @nice2dev/i18n@1.3.10
38
+ - @nice2dev/ui-core@1.3.10
39
+
3
40
  ## 1.3.9
4
41
 
5
42
  ### Patch Changes
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),P=require("@nice2dev/ui-core"),k=require("react"),me=require("react-dom"),he=require("./devops-cgRBnZVX.cjs"),fe=["#ef4444","#f97316","#f59e0b","#84cc16","#10b981","#06b6d4","#3b82f6","#6366f1","#8b5cf6","#ec4899","#64748b","#1e293b"];function ge(){return"#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0")}function ve(a){const u=/^#?([0-9a-f]{6})$/i.exec(a.trim());if(!u)return{r:0,g:0,b:0};const h=parseInt(u[1],16);return{r:h>>16&255,g:h>>8&255,b:h&255}}function be(a,u,h){const p=r=>Math.max(0,Math.min(255,Math.round(r))).toString(16).padStart(2,"0");return`#${p(a)}${p(u)}${p(h)}`}function xe(a,u,h){const p=a/255,r=u/255,i=h/255,n=Math.max(p,r,i),b=Math.min(p,r,i),d=(n+b)/2;let o=0,c=0;if(n!==b){const _=n-b;switch(c=d>.5?_/(2-n-b):_/(n+b),n){case p:o=(r-i)/_+(r<i?6:0);break;case r:o=(i-p)/_+2;break;case i:o=(p-r)/_+4;break}o*=60}return{h:Math.round(o),s:Math.round(c*100),l:Math.round(d*100)}}function _e(a,u,h){const p=u/100,r=h/100,i=(1-Math.abs(2*r-1))*p,n=i*(1-Math.abs(a/60%2-1)),b=r-i/2;let d=0,o=0,c=0;return a<60?[d,o,c]=[i,n,0]:a<120?[d,o,c]=[n,i,0]:a<180?[d,o,c]=[0,i,n]:a<240?[d,o,c]=[0,n,i]:a<300?[d,o,c]=[n,0,i]:[d,o,c]=[i,0,n],{r:Math.round((d+b)*255),g:Math.round((o+b)*255),b:Math.round((c+b)*255)}}function ke(a,u,h){const p=a/255,r=u/255,i=h/255,n=Math.max(p,r,i),b=Math.min(p,r,i),d=n-b;let o=0;d!==0&&(n===p?o=(r-i)/d%6:n===r?o=(i-p)/d+2:o=(p-r)/d+4,o*=60,o<0&&(o+=360));const c=n===0?0:d/n;return{h:Math.round(o),s:Math.round(c*100),v:Math.round(n*100)}}function ye(a,u,h){const p=u/100,r=h/100,i=r*p,n=i*(1-Math.abs(a/60%2-1)),b=r-i;let d=0,o=0,c=0;return a<60?[d,o,c]=[i,n,0]:a<120?[d,o,c]=[n,i,0]:a<180?[d,o,c]=[0,i,n]:a<240?[d,o,c]=[0,n,i]:a<300?[d,o,c]=[n,0,i]:[d,o,c]=[i,0,n],{r:Math.round((d+b)*255),g:Math.round((o+b)*255),b:Math.round((c+b)*255)}}function Ne(a){let u=a.trim();const h=/var\([^,]+,\s*(#[0-9a-fA-F]{3,8})\s*\)/.exec(u);h&&(u=h[1]);const p=/^#?([0-9a-f]{3})$/i.exec(u);p&&(u=`#${p[1].split("").map(n=>n+n).join("")}`);const r=/^#?([0-9a-f]{6})$/i.exec(u),i=/^#?([0-9a-f]{8})$/i.exec(u);if(i){const n=i[1];return{r:parseInt(n.slice(0,2),16),g:parseInt(n.slice(2,4),16),b:parseInt(n.slice(4,6),16),a:parseInt(n.slice(6,8),16)/255}}if(r){const n=parseInt(r[1],16);return{r:n>>16&255,g:n>>8&255,b:n&255,a:1}}return{r:0,g:0,b:0,a:1}}function je(a,u,h,p,r){const i=b=>Math.max(0,Math.min(255,Math.round(b))).toString(16).padStart(2,"0"),n=`#${i(a)}${i(u)}${i(h)}`;return r?`${n}${i(p*255)}`:n}const Me=Object.assign(k.forwardRef(({label:a,helperText:u,error:h,required:p,disabled:r,id:i,className:n,style:b,accessMode:d,displayStyle:o,value:c="#3b82f6",onChange:_,presets:B=fe,showInput:X=!1,showRandom:Y=!1,withAlpha:S=!1,compact:I=!1,showKeyboardHints:J,size:Q="md",labelPlacement:Z,errorPlacement:L,labelWidth:T,controlWidth:D,loading:O},F)=>{const A=P.useNiceAccessMode(d,i),W=A==="hidden";(A==="disabled"||A==="readOnly")&&(r=!0);const{t:v}=P.useNiceTranslation(),$=P.useControlId(i);P.useComponentDisplayClass("input",o);const ee=k.useCallback(()=>{r||_?.(ge())},[r,_]),[M,C]=k.useState(!1),[q,re]=k.useState(null),[K,ne]=k.useState(""),U=k.useRef(null),E=k.useRef(null);k.useLayoutEffect(()=>{if(!M||!E.current)return;ne(he.scopeThemeClass(E.current));const m=()=>{const l=E.current?.getBoundingClientRect();if(!l)return;const N=280,w=360;let x=l.left,j=l.bottom+6;x+N>window.innerWidth-8&&(x=Math.max(8,window.innerWidth-N-8)),j+w>window.innerHeight-8&&(j=Math.max(8,l.top-w-6)),re({left:x,top:j})};return m(),window.addEventListener("scroll",m,!0),window.addEventListener("resize",m),()=>{window.removeEventListener("scroll",m,!0),window.removeEventListener("resize",m)}},[M]),k.useEffect(()=>{if(!M)return;const m=l=>{const N=l.target;U.current?.contains(N)||E.current?.contains(N)||C(!1)};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[M]),P.useOverlayFocus(U,{open:M,modal:!1,onClose:()=>C(!1)});const V=k.useRef(null);P.useRovingFocus(V,{orientation:"grid",itemSelector:".nice-color-picker__preset",wrap:!0});const te=k.useMemo(()=>[{key:"Enter",description:v("shortcuts.openPicker","Open color picker")},{key:"Arrow keys",description:v("shortcuts.navigatePresets","Navigate presets")}],[v]);return W?null:t.jsxs("div",{className:`nice-field nice-field--${Q} ${Z==="left"?"nice-field--label-left":""} ${I?"nice-color-picker--compact":""} ${O?"nice-field--loading":""} ${n||""}`,style:{...b,...T!=null&&{"--nice-field-label-width":typeof T=="number"?`${T}px`:T},...D!=null&&{"--nice-field-control-width":typeof D=="number"?`${D}px`:D}},"aria-busy":O||void 0,children:[a&&t.jsxs("label",{htmlFor:$,className:`nice-field__label ${p?"nice-field__label--required":""}`,children:[a,J&&t.jsx(P.NiceKeyboardHint,{shortcuts:te,size:"sm"})]}),t.jsx("div",{className:"nice-field__control",children:t.jsxs("div",{className:"nice-color-picker",children:[t.jsxs("div",{className:"nice-color-picker__preview-row",children:[t.jsx("div",{ref:E,className:"nice-color-picker__swatch",id:$,style:{background:c},onClick:m=>{m.stopPropagation(),r||C(l=>!l)},onKeyDown:m=>{!r&&(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),C(l=>!l))},role:"button",tabIndex:r?-1:0,"aria-disabled":r||void 0,"aria-label":v("colorPicker.openPalette","Open color palette"),"aria-haspopup":"dialog","aria-expanded":M,children:t.jsx("input",{ref:m=>{typeof F=="function"?F(m):F&&(F.current=m)},type:"hidden",value:c,disabled:r,readOnly:!0})}),X&&t.jsx("div",{className:"nice-input nice-input--sm",style:I?{flex:1,minWidth:0}:{width:100},children:t.jsx("input",{className:"nice-input__native",type:"text",value:c,disabled:r,onChange:m=>_?.(m.target.value),maxLength:S?9:7,"aria-label":v("colorPicker.hexValue","Hex value")})}),Y&&!I&&t.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-color-picker__random",onClick:ee,disabled:r,title:v("colorPicker.random","Random"),"aria-label":v("colorPicker.random","Random"),style:{fontSize:"0.65rem",textTransform:"uppercase",letterSpacing:"0.05em"},children:v("colorPicker.random","Random")}),O&&t.jsx("span",{className:"nice-field__spinner",children:t.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),L==="right"&&h&&t.jsx("div",{id:`${$}-error`,className:"nice-field__error",role:"alert",children:h}),L==="right"&&!h&&u&&t.jsx("div",{id:`${$}-helper`,className:"nice-field__helper",children:u})]}),M&&q&&typeof document<"u"&&me.createPortal(t.jsx("div",{ref:U,className:`nice-color-picker__popup nice-color-picker__popup--portal ${K}`,"data-theme":K==="nice-dark"?"dark":K==="nice-light"?"light":void 0,role:"dialog","aria-label":v("colorPicker.palette","Color palette"),style:{position:"fixed",left:q.left,top:q.top},onClick:m=>m.stopPropagation(),children:(()=>{const m=Ne(c),l={r:m.r,g:m.g,b:m.b},N=S?m.a:1,w=xe(l.r,l.g,l.b),x=ke(l.r,l.g,l.b),j=(e,f,g,s=N)=>_?.(je(e,f,g,s,S)),ie=(e,f,g)=>j(e,f,g),oe=(e,f,g)=>{const s=_e(e,f,g);j(s.r,s.g,s.b)},z=(e,f,g)=>{const s=ye(e,f,g);j(s.r,s.g,s.b)},G=e=>j(l.r,l.g,l.b,e),se=e=>{if(r)return;const f=e.currentTarget,g=y=>{const R=f.getBoundingClientRect(),le=Math.max(0,Math.min(R.width,y.clientX-R.left)),ue=Math.max(0,Math.min(R.height,y.clientY-R.top)),pe=Math.round(le/R.width*100),de=100-Math.round(ue/R.height*100);z(x.h,pe,de)};g(e);const s=()=>{document.removeEventListener("pointermove",g),document.removeEventListener("pointerup",s)};document.addEventListener("pointermove",g),document.addEventListener("pointerup",s)},ae=`hsl(${x.h}, 100%, 50%)`,ce=e=>{if(r)return;const f=e.shiftKey?10:1;let{s:g,v:s}=x;if(e.key==="ArrowLeft")g-=f;else if(e.key==="ArrowRight")g+=f;else if(e.key==="ArrowDown")s-=f;else if(e.key==="ArrowUp")s+=f;else if(e.key==="PageDown")s-=10;else if(e.key==="PageUp")s+=10;else if(e.key==="Home")g=0;else if(e.key==="End")g=100;else return;e.preventDefault(),z(x.h,Math.max(0,Math.min(100,g)),Math.max(0,Math.min(100,s)))},H={h:v("colorPicker.hue","Hue"),s:v("colorPicker.saturation","Saturation"),l:v("colorPicker.lightness","Lightness"),r:v("colorPicker.red","Red"),g:v("colorPicker.green","Green"),b:v("colorPicker.blue","Blue")};return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"nice-color-picker__popup-header",children:t.jsx("input",{type:"text",className:"nice-input__native nice-color-picker__popup-hex",value:c,disabled:r,onChange:e=>_?.(e.target.value),maxLength:S?9:7,"aria-label":v("colorPicker.hexValue","Hex value")})}),t.jsx("input",{type:"range",min:0,max:360,value:x.h,disabled:r,onChange:e=>z(Number(e.target.value),x.s,x.v),className:"nice-color-picker__hue-slider","aria-label":v("colorPicker.hue","Hue")}),t.jsx("div",{className:"nice-color-picker__sv",style:{background:`linear-gradient(to top, var(--nice-text, #000), transparent), linear-gradient(to right, var(--nice-bg, #FFF), ${ae})`},onPointerDown:se,onKeyDown:ce,role:"slider",tabIndex:r?-1:0,"aria-label":v("colorPicker.svPalette","Saturation/value palette"),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":x.s,"aria-valuetext":`${H.s} ${x.s}%, ${v("colorPicker.brightness","Brightness")} ${x.v}%`,children:t.jsx("span",{className:"nice-color-picker__sv-marker",style:{left:`${x.s}%`,top:`${100-x.v}%`}})}),t.jsxs("div",{className:"nice-color-picker__sliders",children:[t.jsx("div",{className:"nice-color-picker__slider-col",children:["h","s","l"].map(e=>{const f=e==="h"?360:100,g=w[e],s=y=>oe(e==="h"?y:w.h,e==="s"?y:w.s,e==="l"?y:w.l);return t.jsxs("div",{className:"nice-color-picker__slider-row",children:[t.jsx("label",{className:"nice-color-picker__slider-label",children:e.toUpperCase()}),t.jsx("input",{type:"range",min:0,max:f,value:g,disabled:r,onChange:y=>s(Number(y.target.value)),"aria-label":H[e]}),t.jsx("input",{type:"number",min:0,max:f,value:g,disabled:r,onChange:y=>s(Number(y.target.value)||0),className:"nice-input__native nice-color-picker__slider-num","aria-label":H[e]})]},e)})}),t.jsx("div",{className:"nice-color-picker__slider-col",children:["r","g","b"].map(e=>{const f=l[e],g=s=>ie(e==="r"?s:l.r,e==="g"?s:l.g,e==="b"?s:l.b);return t.jsxs("div",{className:"nice-color-picker__slider-row",children:[t.jsx("label",{className:"nice-color-picker__slider-label",children:e.toUpperCase()}),t.jsx("input",{type:"range",min:0,max:255,value:f,disabled:r,onChange:s=>g(Number(s.target.value)),"aria-label":H[e]}),t.jsx("input",{type:"number",min:0,max:255,value:f,disabled:r,onChange:s=>g(Number(s.target.value)||0),className:"nice-input__native nice-color-picker__slider-num","aria-label":H[e]})]},e)})})]}),S&&t.jsxs("div",{className:"nice-color-picker__alpha-row",children:[t.jsx("label",{className:"nice-color-picker__slider-label",children:"A"}),t.jsx("input",{type:"range",min:0,max:100,value:Math.round(N*100),disabled:r,onChange:e=>G(Number(e.target.value)/100),className:"nice-color-picker__alpha-slider",style:{background:`linear-gradient(to right, transparent, rgb(${l.r},${l.g},${l.b}))`},"aria-label":v("colorPicker.alpha","Alpha")}),t.jsx("input",{type:"number",min:0,max:100,value:Math.round(N*100),disabled:r,onChange:e=>G((Number(e.target.value)||0)/100),className:"nice-input__native nice-color-picker__slider-num","aria-label":v("colorPicker.alpha","Alpha")})]}),B.length>0&&t.jsx("div",{ref:V,className:"nice-color-picker__popup-presets",role:"group","aria-label":v("colorPicker.presets","Preset colors"),children:B.map(e=>t.jsx("div",{className:`nice-color-picker__preset ${c===e?"nice-color-picker__preset--active":""}`,style:{background:e},onClick:()=>{_?.(e),C(!1)},role:"button","aria-label":e,"aria-pressed":c===e,onKeyDown:f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),_?.(e),C(!1))}},e))})]})})()}),document.body)]})}),L!=="right"&&h&&t.jsx("div",{id:`${$}-error`,className:"nice-field__error",role:"alert",children:h}),L!=="right"&&!h&&u&&t.jsx("div",{id:`${$}-helper`,className:"nice-field__helper",children:u})]})}),{displayName:"NiceColorPicker"});exports.NiceColorPicker=Me;exports.hexToRgb=ve;exports.rgbToHex=be;
@@ -0,0 +1,552 @@
1
+ import { jsxs as x, jsx as i, Fragment as he } from "react/jsx-runtime";
2
+ import { useNiceAccessMode as fe, useNiceTranslation as ge, useControlId as ve, useComponentDisplayClass as be, useOverlayFocus as _e, useRovingFocus as ke, NiceKeyboardHint as ye } from "@nice2dev/ui-core";
3
+ import { forwardRef as Ne, useCallback as xe, useState as B, useRef as V, useLayoutEffect as Me, useEffect as we, useMemo as $e } from "react";
4
+ import Pe from "react-dom";
5
+ import { s as Ce } from "./devops-CqhA0rjL.js";
6
+ const Re = [
7
+ "#ef4444",
8
+ "#f97316",
9
+ "#f59e0b",
10
+ "#84cc16",
11
+ "#10b981",
12
+ "#06b6d4",
13
+ "#3b82f6",
14
+ "#6366f1",
15
+ "#8b5cf6",
16
+ "#ec4899",
17
+ "#64748b",
18
+ "#1e293b"
19
+ ];
20
+ function Ee() {
21
+ return "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0");
22
+ }
23
+ function je(c) {
24
+ const u = /^#?([0-9a-f]{6})$/i.exec(c.trim());
25
+ if (!u)
26
+ return { r: 0, g: 0, b: 0 };
27
+ const h = parseInt(u[1], 16);
28
+ return { r: h >> 16 & 255, g: h >> 8 & 255, b: h & 255 };
29
+ }
30
+ function ze(c, u, h) {
31
+ const p = (r) => Math.max(0, Math.min(255, Math.round(r))).toString(16).padStart(2, "0");
32
+ return `#${p(c)}${p(u)}${p(h)}`;
33
+ }
34
+ function Se(c, u, h) {
35
+ const p = c / 255, r = u / 255, t = h / 255, n = Math.max(p, r, t), b = Math.min(p, r, t), m = (n + b) / 2;
36
+ let o = 0, s = 0;
37
+ if (n !== b) {
38
+ const k = n - b;
39
+ switch (s = m > 0.5 ? k / (2 - n - b) : k / (n + b), n) {
40
+ case p:
41
+ o = (r - t) / k + (r < t ? 6 : 0);
42
+ break;
43
+ case r:
44
+ o = (t - p) / k + 2;
45
+ break;
46
+ case t:
47
+ o = (p - r) / k + 4;
48
+ break;
49
+ }
50
+ o *= 60;
51
+ }
52
+ return { h: Math.round(o), s: Math.round(s * 100), l: Math.round(m * 100) };
53
+ }
54
+ function He(c, u, h) {
55
+ const p = u / 100, r = h / 100, t = (1 - Math.abs(2 * r - 1)) * p, n = t * (1 - Math.abs(c / 60 % 2 - 1)), b = r - t / 2;
56
+ let m = 0, o = 0, s = 0;
57
+ return c < 60 ? [m, o, s] = [t, n, 0] : c < 120 ? [m, o, s] = [n, t, 0] : c < 180 ? [m, o, s] = [0, t, n] : c < 240 ? [m, o, s] = [0, n, t] : c < 300 ? [m, o, s] = [n, 0, t] : [m, o, s] = [t, 0, n], {
58
+ r: Math.round((m + b) * 255),
59
+ g: Math.round((o + b) * 255),
60
+ b: Math.round((s + b) * 255)
61
+ };
62
+ }
63
+ function Le(c, u, h) {
64
+ const p = c / 255, r = u / 255, t = h / 255, n = Math.max(p, r, t), b = Math.min(p, r, t), m = n - b;
65
+ let o = 0;
66
+ m !== 0 && (n === p ? o = (r - t) / m % 6 : n === r ? o = (t - p) / m + 2 : o = (p - r) / m + 4, o *= 60, o < 0 && (o += 360));
67
+ const s = n === 0 ? 0 : m / n;
68
+ return { h: Math.round(o), s: Math.round(s * 100), v: Math.round(n * 100) };
69
+ }
70
+ function De(c, u, h) {
71
+ const p = u / 100, r = h / 100, t = r * p, n = t * (1 - Math.abs(c / 60 % 2 - 1)), b = r - t;
72
+ let m = 0, o = 0, s = 0;
73
+ return c < 60 ? [m, o, s] = [t, n, 0] : c < 120 ? [m, o, s] = [n, t, 0] : c < 180 ? [m, o, s] = [0, t, n] : c < 240 ? [m, o, s] = [0, n, t] : c < 300 ? [m, o, s] = [n, 0, t] : [m, o, s] = [t, 0, n], {
74
+ r: Math.round((m + b) * 255),
75
+ g: Math.round((o + b) * 255),
76
+ b: Math.round((s + b) * 255)
77
+ };
78
+ }
79
+ function Te(c) {
80
+ let u = c.trim();
81
+ const h = /var\([^,]+,\s*(#[0-9a-fA-F]{3,8})\s*\)/.exec(u);
82
+ h && (u = h[1]);
83
+ const p = /^#?([0-9a-f]{3})$/i.exec(u);
84
+ p && (u = `#${p[1].split("").map((n) => n + n).join("")}`);
85
+ const r = /^#?([0-9a-f]{6})$/i.exec(u), t = /^#?([0-9a-f]{8})$/i.exec(u);
86
+ if (t) {
87
+ const n = t[1];
88
+ return {
89
+ r: parseInt(n.slice(0, 2), 16),
90
+ g: parseInt(n.slice(2, 4), 16),
91
+ b: parseInt(n.slice(4, 6), 16),
92
+ a: parseInt(n.slice(6, 8), 16) / 255
93
+ };
94
+ }
95
+ if (r) {
96
+ const n = parseInt(r[1], 16);
97
+ return { r: n >> 16 & 255, g: n >> 8 & 255, b: n & 255, a: 1 };
98
+ }
99
+ return { r: 0, g: 0, b: 0, a: 1 };
100
+ }
101
+ function Fe(c, u, h, p, r) {
102
+ const t = (b) => Math.max(0, Math.min(255, Math.round(b))).toString(16).padStart(2, "0"), n = `#${t(c)}${t(u)}${t(h)}`;
103
+ return r ? `${n}${t(p * 255)}` : n;
104
+ }
105
+ const Be = /* @__PURE__ */ Object.assign(
106
+ /* @__PURE__ */ Ne(
107
+ ({
108
+ label: c,
109
+ helperText: u,
110
+ error: h,
111
+ required: p,
112
+ disabled: r,
113
+ id: t,
114
+ className: n,
115
+ style: b,
116
+ accessMode: m,
117
+ displayStyle: o,
118
+ value: s = "#3b82f6",
119
+ onChange: k,
120
+ presets: q = Re,
121
+ showInput: Y = !1,
122
+ showRandom: J = !1,
123
+ withAlpha: E = !1,
124
+ compact: I = !1,
125
+ showKeyboardHints: Q,
126
+ size: Z = "md",
127
+ labelPlacement: W,
128
+ errorPlacement: L,
129
+ labelWidth: D,
130
+ controlWidth: T,
131
+ loading: A
132
+ }, F) => {
133
+ const O = fe(m, t), ee = O === "hidden";
134
+ (O === "disabled" || O === "readOnly") && (r = !0);
135
+ const { t: v } = ge(), P = ve(t);
136
+ be("input", o);
137
+ const re = xe(() => {
138
+ r || k?.(Ee());
139
+ }, [r, k]), [w, C] = B(!1), [K, ne] = B(null), [U, te] = B(""), j = V(null), S = V(null);
140
+ Me(() => {
141
+ if (!w || !S.current)
142
+ return;
143
+ te(Ce(S.current));
144
+ const d = () => {
145
+ const l = S.current?.getBoundingClientRect();
146
+ if (!l)
147
+ return;
148
+ const N = 280, $ = 360;
149
+ let _ = l.left, M = l.bottom + 6;
150
+ _ + N > window.innerWidth - 8 && (_ = Math.max(8, window.innerWidth - N - 8)), M + $ > window.innerHeight - 8 && (M = Math.max(8, l.top - $ - 6)), ne({ left: _, top: M });
151
+ };
152
+ return d(), window.addEventListener("scroll", d, !0), window.addEventListener("resize", d), () => {
153
+ window.removeEventListener("scroll", d, !0), window.removeEventListener("resize", d);
154
+ };
155
+ }, [w]), we(() => {
156
+ if (!w)
157
+ return;
158
+ const d = (l) => {
159
+ const N = l.target;
160
+ j.current?.contains(N) || S.current?.contains(N) || C(!1);
161
+ };
162
+ return document.addEventListener("mousedown", d), () => {
163
+ document.removeEventListener("mousedown", d);
164
+ };
165
+ }, [w]), _e(j, {
166
+ open: w,
167
+ modal: !1,
168
+ onClose: () => C(!1)
169
+ });
170
+ const G = V(null);
171
+ ke(G, {
172
+ orientation: "grid",
173
+ itemSelector: ".nice-color-picker__preset",
174
+ wrap: !0
175
+ });
176
+ const ie = $e(
177
+ () => [
178
+ { key: "Enter", description: v("shortcuts.openPicker", "Open color picker") },
179
+ { key: "Arrow keys", description: v("shortcuts.navigatePresets", "Navigate presets") }
180
+ ],
181
+ [v]
182
+ );
183
+ return ee ? null : /* @__PURE__ */ x(
184
+ "div",
185
+ {
186
+ className: `nice-field nice-field--${Z} ${W === "left" ? "nice-field--label-left" : ""} ${I ? "nice-color-picker--compact" : ""} ${A ? "nice-field--loading" : ""} ${n || ""}`,
187
+ style: {
188
+ ...b,
189
+ ...D != null && {
190
+ "--nice-field-label-width": typeof D == "number" ? `${D}px` : D
191
+ },
192
+ ...T != null && {
193
+ "--nice-field-control-width": typeof T == "number" ? `${T}px` : T
194
+ }
195
+ },
196
+ "aria-busy": A || void 0,
197
+ children: [
198
+ c && /* @__PURE__ */ x(
199
+ "label",
200
+ {
201
+ htmlFor: P,
202
+ className: `nice-field__label ${p ? "nice-field__label--required" : ""}`,
203
+ children: [
204
+ c,
205
+ Q && /* @__PURE__ */ i(ye, { shortcuts: ie, size: "sm" })
206
+ ]
207
+ }
208
+ ),
209
+ /* @__PURE__ */ i("div", { className: "nice-field__control", children: /* @__PURE__ */ x("div", { className: "nice-color-picker", children: [
210
+ /* @__PURE__ */ x("div", { className: "nice-color-picker__preview-row", children: [
211
+ /* @__PURE__ */ i(
212
+ "div",
213
+ {
214
+ ref: S,
215
+ className: "nice-color-picker__swatch",
216
+ id: P,
217
+ style: { background: s },
218
+ onClick: (d) => {
219
+ d.stopPropagation(), r || C((l) => !l);
220
+ },
221
+ onKeyDown: (d) => {
222
+ !r && (d.key === "Enter" || d.key === " ") && (d.preventDefault(), C((l) => !l));
223
+ },
224
+ role: "button",
225
+ tabIndex: r ? -1 : 0,
226
+ "aria-disabled": r || void 0,
227
+ "aria-label": v("colorPicker.openPalette", "Open color palette"),
228
+ "aria-haspopup": "dialog",
229
+ "aria-expanded": w,
230
+ children: /* @__PURE__ */ i(
231
+ "input",
232
+ {
233
+ ref: (d) => {
234
+ typeof F == "function" ? F(d) : F && (F.current = d);
235
+ },
236
+ type: "hidden",
237
+ value: s,
238
+ disabled: r,
239
+ readOnly: !0
240
+ }
241
+ )
242
+ }
243
+ ),
244
+ Y && /* @__PURE__ */ i(
245
+ "div",
246
+ {
247
+ className: "nice-input nice-input--sm",
248
+ style: I ? { flex: 1, minWidth: 0 } : { width: 100 },
249
+ children: /* @__PURE__ */ i(
250
+ "input",
251
+ {
252
+ className: "nice-input__native",
253
+ type: "text",
254
+ value: s,
255
+ disabled: r,
256
+ onChange: (d) => k?.(d.target.value),
257
+ maxLength: E ? 9 : 7,
258
+ "aria-label": v("colorPicker.hexValue", "Hex value")
259
+ }
260
+ )
261
+ }
262
+ ),
263
+ J && !I && /* @__PURE__ */ i(
264
+ "button",
265
+ {
266
+ type: "button",
267
+ className: "nice-btn nice-btn--outline nice-btn--sm nice-color-picker__random",
268
+ onClick: re,
269
+ disabled: r,
270
+ title: v("colorPicker.random", "Random"),
271
+ "aria-label": v("colorPicker.random", "Random"),
272
+ style: {
273
+ fontSize: "0.65rem",
274
+ textTransform: "uppercase",
275
+ letterSpacing: "0.05em"
276
+ },
277
+ children: v("colorPicker.random", "Random")
278
+ }
279
+ ),
280
+ A && /* @__PURE__ */ i("span", { className: "nice-field__spinner", children: /* @__PURE__ */ i("span", { className: "nice-spinner nice-spinner--sm" }) }),
281
+ L === "right" && h && /* @__PURE__ */ i("div", { id: `${P}-error`, className: "nice-field__error", role: "alert", children: h }),
282
+ L === "right" && !h && u && /* @__PURE__ */ i("div", { id: `${P}-helper`, className: "nice-field__helper", children: u })
283
+ ] }),
284
+ w && K && typeof document < "u" && Pe.createPortal(
285
+ // stopPropagation keeps a click inside the palette from reaching the closer
286
+ // listening outside it; it is no interaction of its own
287
+ // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions -- no interaction of its own: it keeps a click inside the palette from the closer outside it
288
+ /* @__PURE__ */ i(
289
+ "div",
290
+ {
291
+ ref: j,
292
+ className: `nice-color-picker__popup nice-color-picker__popup--portal ${U}`,
293
+ "data-theme": U === "nice-dark" ? "dark" : U === "nice-light" ? "light" : void 0,
294
+ role: "dialog",
295
+ "aria-label": v("colorPicker.palette", "Color palette"),
296
+ style: { position: "fixed", left: K.left, top: K.top },
297
+ onClick: (d) => d.stopPropagation(),
298
+ children: (() => {
299
+ const d = Te(s), l = { r: d.r, g: d.g, b: d.b }, N = E ? d.a : 1, $ = Se(l.r, l.g, l.b), _ = Le(l.r, l.g, l.b), M = (e, f, g, a = N) => k?.(Fe(e, f, g, a, E)), oe = (e, f, g) => M(e, f, g), ae = (e, f, g) => {
300
+ const a = He(e, f, g);
301
+ M(a.r, a.g, a.b);
302
+ }, z = (e, f, g) => {
303
+ const a = De(e, f, g);
304
+ M(a.r, a.g, a.b);
305
+ }, X = (e) => M(l.r, l.g, l.b, e), ce = (e) => {
306
+ if (r)
307
+ return;
308
+ const f = e.currentTarget, g = (y) => {
309
+ const R = f.getBoundingClientRect(), ue = Math.max(0, Math.min(R.width, y.clientX - R.left)), pe = Math.max(0, Math.min(R.height, y.clientY - R.top)), me = Math.round(ue / R.width * 100), de = 100 - Math.round(pe / R.height * 100);
310
+ z(_.h, me, de);
311
+ };
312
+ g(e);
313
+ const a = () => {
314
+ document.removeEventListener("pointermove", g), document.removeEventListener("pointerup", a);
315
+ };
316
+ document.addEventListener("pointermove", g), document.addEventListener("pointerup", a);
317
+ }, se = `hsl(${_.h}, 100%, 50%)`, le = (e) => {
318
+ if (r)
319
+ return;
320
+ const f = e.shiftKey ? 10 : 1;
321
+ let { s: g, v: a } = _;
322
+ if (e.key === "ArrowLeft")
323
+ g -= f;
324
+ else if (e.key === "ArrowRight")
325
+ g += f;
326
+ else if (e.key === "ArrowDown")
327
+ a -= f;
328
+ else if (e.key === "ArrowUp")
329
+ a += f;
330
+ else if (e.key === "PageDown")
331
+ a -= 10;
332
+ else if (e.key === "PageUp")
333
+ a += 10;
334
+ else if (e.key === "Home")
335
+ g = 0;
336
+ else if (e.key === "End")
337
+ g = 100;
338
+ else
339
+ return;
340
+ e.preventDefault(), z(_.h, Math.max(0, Math.min(100, g)), Math.max(0, Math.min(100, a)));
341
+ }, H = {
342
+ h: v("colorPicker.hue", "Hue"),
343
+ s: v("colorPicker.saturation", "Saturation"),
344
+ l: v("colorPicker.lightness", "Lightness"),
345
+ r: v("colorPicker.red", "Red"),
346
+ g: v("colorPicker.green", "Green"),
347
+ b: v("colorPicker.blue", "Blue")
348
+ };
349
+ return /* @__PURE__ */ x(he, { children: [
350
+ /* @__PURE__ */ i("div", { className: "nice-color-picker__popup-header", children: /* @__PURE__ */ i(
351
+ "input",
352
+ {
353
+ type: "text",
354
+ className: "nice-input__native nice-color-picker__popup-hex",
355
+ value: s,
356
+ disabled: r,
357
+ onChange: (e) => k?.(e.target.value),
358
+ maxLength: E ? 9 : 7,
359
+ "aria-label": v("colorPicker.hexValue", "Hex value")
360
+ }
361
+ ) }),
362
+ /* @__PURE__ */ i(
363
+ "input",
364
+ {
365
+ type: "range",
366
+ min: 0,
367
+ max: 360,
368
+ value: _.h,
369
+ disabled: r,
370
+ onChange: (e) => z(Number(e.target.value), _.s, _.v),
371
+ className: "nice-color-picker__hue-slider",
372
+ "aria-label": v("colorPicker.hue", "Hue")
373
+ }
374
+ ),
375
+ /* @__PURE__ */ i(
376
+ "div",
377
+ {
378
+ className: "nice-color-picker__sv",
379
+ style: {
380
+ /* audit-allow: token-role — black letterbox / canvas fill. A video frame or a
381
+ drawing surface is not a themed surface, so it stays black in both themes. */
382
+ background: `linear-gradient(to top, var(--nice-text, #000), transparent), linear-gradient(to right, var(--nice-bg, #FFF), ${se})`
383
+ },
384
+ onPointerDown: ce,
385
+ onKeyDown: le,
386
+ role: "slider",
387
+ tabIndex: r ? -1 : 0,
388
+ "aria-label": v("colorPicker.svPalette", "Saturation/value palette"),
389
+ "aria-valuemin": 0,
390
+ "aria-valuemax": 100,
391
+ "aria-valuenow": _.s,
392
+ "aria-valuetext": `${H.s} ${_.s}%, ${v("colorPicker.brightness", "Brightness")} ${_.v}%`,
393
+ children: /* @__PURE__ */ i(
394
+ "span",
395
+ {
396
+ className: "nice-color-picker__sv-marker",
397
+ style: { left: `${_.s}%`, top: `${100 - _.v}%` }
398
+ }
399
+ )
400
+ }
401
+ ),
402
+ /* @__PURE__ */ x("div", { className: "nice-color-picker__sliders", children: [
403
+ /* @__PURE__ */ i("div", { className: "nice-color-picker__slider-col", children: ["h", "s", "l"].map((e) => {
404
+ const f = e === "h" ? 360 : 100, g = $[e], a = (y) => ae(
405
+ e === "h" ? y : $.h,
406
+ e === "s" ? y : $.s,
407
+ e === "l" ? y : $.l
408
+ );
409
+ return /* @__PURE__ */ x("div", { className: "nice-color-picker__slider-row", children: [
410
+ /* @__PURE__ */ i("label", { className: "nice-color-picker__slider-label", children: e.toUpperCase() }),
411
+ /* @__PURE__ */ i(
412
+ "input",
413
+ {
414
+ type: "range",
415
+ min: 0,
416
+ max: f,
417
+ value: g,
418
+ disabled: r,
419
+ onChange: (y) => a(Number(y.target.value)),
420
+ "aria-label": H[e]
421
+ }
422
+ ),
423
+ /* @__PURE__ */ i(
424
+ "input",
425
+ {
426
+ type: "number",
427
+ min: 0,
428
+ max: f,
429
+ value: g,
430
+ disabled: r,
431
+ onChange: (y) => a(Number(y.target.value) || 0),
432
+ className: "nice-input__native nice-color-picker__slider-num",
433
+ "aria-label": H[e]
434
+ }
435
+ )
436
+ ] }, e);
437
+ }) }),
438
+ /* @__PURE__ */ i("div", { className: "nice-color-picker__slider-col", children: ["r", "g", "b"].map((e) => {
439
+ const f = l[e], g = (a) => oe(
440
+ e === "r" ? a : l.r,
441
+ e === "g" ? a : l.g,
442
+ e === "b" ? a : l.b
443
+ );
444
+ return /* @__PURE__ */ x("div", { className: "nice-color-picker__slider-row", children: [
445
+ /* @__PURE__ */ i("label", { className: "nice-color-picker__slider-label", children: e.toUpperCase() }),
446
+ /* @__PURE__ */ i(
447
+ "input",
448
+ {
449
+ type: "range",
450
+ min: 0,
451
+ max: 255,
452
+ value: f,
453
+ disabled: r,
454
+ onChange: (a) => g(Number(a.target.value)),
455
+ "aria-label": H[e]
456
+ }
457
+ ),
458
+ /* @__PURE__ */ i(
459
+ "input",
460
+ {
461
+ type: "number",
462
+ min: 0,
463
+ max: 255,
464
+ value: f,
465
+ disabled: r,
466
+ onChange: (a) => g(Number(a.target.value) || 0),
467
+ className: "nice-input__native nice-color-picker__slider-num",
468
+ "aria-label": H[e]
469
+ }
470
+ )
471
+ ] }, e);
472
+ }) })
473
+ ] }),
474
+ E && /* @__PURE__ */ x("div", { className: "nice-color-picker__alpha-row", children: [
475
+ /* @__PURE__ */ i("label", { className: "nice-color-picker__slider-label", children: "A" }),
476
+ /* @__PURE__ */ i(
477
+ "input",
478
+ {
479
+ type: "range",
480
+ min: 0,
481
+ max: 100,
482
+ value: Math.round(N * 100),
483
+ disabled: r,
484
+ onChange: (e) => X(Number(e.target.value) / 100),
485
+ className: "nice-color-picker__alpha-slider",
486
+ style: {
487
+ background: `linear-gradient(to right, transparent, rgb(${l.r},${l.g},${l.b}))`
488
+ },
489
+ "aria-label": v("colorPicker.alpha", "Alpha")
490
+ }
491
+ ),
492
+ /* @__PURE__ */ i(
493
+ "input",
494
+ {
495
+ type: "number",
496
+ min: 0,
497
+ max: 100,
498
+ value: Math.round(N * 100),
499
+ disabled: r,
500
+ onChange: (e) => X((Number(e.target.value) || 0) / 100),
501
+ className: "nice-input__native nice-color-picker__slider-num",
502
+ "aria-label": v("colorPicker.alpha", "Alpha")
503
+ }
504
+ )
505
+ ] }),
506
+ q.length > 0 && /* @__PURE__ */ i(
507
+ "div",
508
+ {
509
+ ref: G,
510
+ className: "nice-color-picker__popup-presets",
511
+ role: "group",
512
+ "aria-label": v("colorPicker.presets", "Preset colors"),
513
+ children: q.map((e) => /* @__PURE__ */ i(
514
+ "div",
515
+ {
516
+ className: `nice-color-picker__preset ${s === e ? "nice-color-picker__preset--active" : ""}`,
517
+ style: { background: e },
518
+ onClick: () => {
519
+ k?.(e), C(!1);
520
+ },
521
+ role: "button",
522
+ "aria-label": e,
523
+ "aria-pressed": s === e,
524
+ onKeyDown: (f) => {
525
+ (f.key === "Enter" || f.key === " ") && (f.preventDefault(), k?.(e), C(!1));
526
+ }
527
+ },
528
+ e
529
+ ))
530
+ }
531
+ )
532
+ ] });
533
+ })()
534
+ }
535
+ ),
536
+ document.body
537
+ )
538
+ ] }) }),
539
+ L !== "right" && h && /* @__PURE__ */ i("div", { id: `${P}-error`, className: "nice-field__error", role: "alert", children: h }),
540
+ L !== "right" && !h && u && /* @__PURE__ */ i("div", { id: `${P}-helper`, className: "nice-field__helper", children: u })
541
+ ]
542
+ }
543
+ );
544
+ }
545
+ ),
546
+ { displayName: "NiceColorPicker" }
547
+ );
548
+ export {
549
+ Be as NiceColorPicker,
550
+ je as hexToRgb,
551
+ ze as rgbToHex
552
+ };